Program Hamman;
USES HamLib, CRT, DOS;
VAR R : Real;

PROCEDURE WaitForKey;
BEGIN
  Write('-=:[PRESS ANY KEY]:=-');
  IF Readkey = #0 THEN ;
END;

PROCEDURE Center(S : STRING; Fg : Byte);
BEGIN
  TextColor(Fg);
  GotoXy((40 - (Length(S) DIV 2)),WhereY);
  Write(S);
END;

PROCEDURE ShowGroundPlane;
VAR Freq : REAL;
    St,Ra,Total : REAL;


BEGIN
  Clrscr;
  Write('Frequency: '); Readln(Freq);
  Clrscr;
  St := M2In(Wavelength(Freq)) / 4;
  Ra := St * 1.05;
  Total := St + (4 * Ra);
  Center('Quarter Wave Ground Plane Plans',LightCyan); WriteLn; Writeln;
  WriteLn('For a quarter wave ground plane tuned to frequency ',Freq:9:4);
  WriteLn('you will need a total of ',In2Ft(Total):9:2,' Feet of Wire, or');
  WriteLn('copper tubing, etc.');
  WriteLn('Cut 4 wires to ',Ra:9:2,' Inches, and one wire to ',St:9:2,' inches.');
  WriteLn('The 1 Wire cut to ',St:9:2,' should be soldered to the center conductor');
  Writeln('of the SO-239, while the 4 wires cut to ',RA:9:2,' inches should be ');
  Writeln('connected to each of the 4 screw terminals (The ground) of the SO-239');
  Writeln('Mount the SO-239 through a PVC cap and place on a tall PVC pipe.  Mount');
  Writeln('as high as possible for best results.');
  Waitforkey;
END;

PROCEDURE ShowDiPole;
VAR Freq : REAL;
    St,Total : REAL;

BEGIN
  Clrscr;
  Write('Frequency: '); Readln(Freq);
  Clrscr;
  St := M2In(Wavelength(Freq)) / 2;
  Total :=  2 * St;
  Center('Di-Pole Plans',LightCyan); WriteLn; Writeln;
  WriteLn('For a Di-Pole tuned to frequency ',Freq:9:4);
  WriteLn('you will need a total of ',In2Ft(Total):9:2,' Feet of Wire, or');
  WriteLn('copper tubing, etc.');
  WriteLn('Cut 2 wires to ',st:9:2,' Inches.');
  WriteLn('Solder one wire to the center of a SO-239, the other to the ground.');
  Writeln('The optimum height of the di-pole would be ',St:9:2,' Inches above the ground.');
  Waitforkey;
END;

PROCEDURE ShowWaveLength;
VAR Freq : REAL;
    A,B  : REAL;

BEGIN
        Clrscr;
        Write('Frequency: ');
        Readln(Freq);
        Clrscr;
        Writeln('At Frequency of ',Freq:9:4,' the wave length would be');
        Writeln(Wavelength(Freq):9:3,' Meters or');
        WriteLn((M2Ft(Wavelength(Freq))/3):9:3,' Yards, or ');
        Writeln(M2Ft(Wavelength(Freq)):9:3,' Feet, or');
        WriteLn(M2CM(WaveLength(Freq)):9:3,' Centimeters, or ');
        WriteLn(M2MM(WaveLength(Freq)):9:3,' Millimeters, or ');
        WriteLn(M2In(WaveLength(Freq)):9:2,' Inches.');

        WaitForKey;
END;

PROCEDURE ShowCurrentVoltResistance;
VAR I,V,R : Real;
BEGIN
        Clrscr;
        Write('Voltage: '); Readln(V);
        Write('Resistance: '); ReadLn(R);
        I := V / R;
        Writeln('Current = ',I:7:3,' Amps');
        WaitForKey;
END;

PROCEDURE ShowE_IR;
VAR E,I,R : REAL;
BEGIN
        Clrscr;
        Write('Current (amps): '); Readln(I);
        Write('Resistance (ohms): '); Readln(R);
        E := I * R;
        Writeln('Power = ',E:9:3,' Watts.');
        WaitForKey;
END;

PROCEDURE ShowI_ER;
VAR E,I,R : REAL;
BEGIN
        Clrscr;
        Write('    Power (Watts): '); Readln(E);
        Write('Resistance (Ohms): '); Readln(R);
        I := E / R;
        Writeln('         Current = ',I:9:3,' Amps');
        WaitForKey;
END;

PROCEDURE ShowFormulas;
BEGIN
        Clrscr;
        TextColor(white);
        Writeln('OHM''s Law:'); Writeln; TextColor(Yellow);
        Writeln('E=IR  Eagle looks down and sees an Indian standing beside a rabbit');
        Writeln('I=E/R Indian looks down and sees an Eagle over a Rabbit!');
        Writeln('R=E/I Rabbit looks beyond and sees an Eagle over an Indian!');
        Writeln('V=IR  The Vulcan looks onward and sees an Indian standing next to a rabbit');
        Writeln('I=V/R The Indian sees a Vulcan standing on a flattened Rabbit!');
        Writeln('R=V/I The Scared Rabbit sees a Vulcan standing on an indian');
        Writeln('E=V/I The Eagle sees a Vulcan on top of an Indian and leaves');
        Writeln('V=EI  The Vulcan notices an Eagle next to an Indian!');
        Writeln('I=E/V The Indian notices an Eagle Flying over a Vulcan!');
        WaitForKey;
END;

PROCEDURE MenuOption(Ln : byte; Key : Char; Desc : String);
BEGIN
  GotoXy(1,Ln);
  TextColor(White);      Write('[');
  TextColor(LightGreen); Write(Key);
  TextColor(White);      Write('] ');
  TextColor(Yellow);     Write(Desc);
END;

PROCEDURE ShowOhmsLaw;
VAR Done : BOOLEAN;
    CH : Char;

BEGIN
  Done := False;
  REPEAT
    TextBackground(Black);
    Clrscr;
    Center('OHM''s Law Menu',15); Writeln; Writeln;
    MenuOption(3,'1','Calculate Current from Volts and Resistance');
    MenuOption(4,'2','Calculate Power from Current and Resistance');
    MenuOption(5,'3','Calculate Current from Power and Resistance');
    MenuOption(6,'4','Show Formulas');
    MenuOption(7,'Q','Quit to main'); Writeln; Writeln;
    TextColor(LightGreen);
    Write('Choice: ');
    Ch := Upcase(Readkey);
    Case CH of
       'Q' : Done := True;
       '1' : ShowCurrentVoltResistance;
       '2' : ShowE_IR;
       '3' : ShowI_ER;
       '4' : ShowFormulas;
    END;
  UNTIL DONE;
END;

PROCEDURE MainMenu;
VAR Done : BOOLEAN;
     Ch  : Char;

BEGIN
  Done := False;
  WHILE NOT DONE DO BEGIN
    Clrscr;
    TextBackground(Black);
    Center('Ham Man v1.00b',White);
    MenuOption(3,'1','Wave Length');
    MenuOption(4,'2','Ground Plane');
    MenuOption(5,'3','Di-Pole');
    MenuOption(6,'4','Ohm''s Law Menu');
    MenuOption(7,'Q','Quit');
    Writeln;
    Writeln;
    TextColor(LightGreen);
    Write('Choice: ');
    textColor(LightCyan);
    Ch := Upcase(ReadKey);
    Case CH of
      '1' : ShowWaveLength;
      '2' : ShowGroundPlane;
      '3' : ShowDipole;
      '4' : ShowOhmsLaw;
      'Q' : Done := True;
    END;
  END;
END;

BEGIN
  MainMenu;
END.
